// 主要列表页
// 搜索栏表单组件
import FInput from '@/components/form/f-input'
import FInputAutocomplete from '@/components/form/f-input-autocomplete'
import FSelect from '@/components/form/f-select'
import FSelectCascader from '@/components/form/f-select-cascader'
import FDatePicker from '@/components/form/f-date-picker'
// 页面布局组件
import SearchBar from '@/components/table/search-bar'
import ButtonImport from '@/components/table/button-import'
import Table from '@/components/table/table'
import ExportData from '@/components/table/export-data'
import Pagination from '@/components/table/pagination'
// 分页
import { PAGE } from '@/constants/public'

export default {
  components: {
    // 搜索栏表单组件
    FInput,
    FInputAutocomplete,
    FSelect,
    FSelectCascader,
    FDatePicker,
    // 页面布局组件
    SearchBar,
    ButtonImport,
    Table,
    ExportData,
    // 分页
    Pagination
  },
  data() {
    return {
      searchData: {}, // 查询列表数据参数
      searchDataParams: {}, // 用于请求数据时参数隔离
      page: { ...PAGE }, // 分页对象
      pageList: [], // 分页列表
      tableLoading: false, // 表格加载中
      selectData: [], // 被选中的列表
      // 弹框: 新增+编辑+详情
      editParams: {
        title: '',
        show: false,
        data: null
      }
    }
  },
  mounted() {
    this.resetForm()
  },
  methods: {
    /**
     * 重置表单
     */
    resetForm() {
      this.searchData = {}
      this.queryList()
    },
    /**
     * 通过条件查询数据 将请求参数隔离避免参数污染
     */
    queryList() {
      this.page.currPage = 1
      this.searchDataParams = { ...this.searchData }
      this.getList()
    },
    /**
     * 获取列表之前调用的函数，处理通用字段
     */
    getListBefore() {
      this.searchDataParams.currPage = this.page.currPage
      this.searchDataParams.limit = this.page.limit
      this.pageList = []
      this.tableLoading = true
    },
    /**
     * 新增+编辑+详情
     * @param {Object} title
     * @param {Object} row
     */
    edit(title, row) {
      if (row) {
        this.editParams.data = { ...row }
      } else {
        this.editParams.data = null
      }
      this.editParams.title = title
      this.editParams.show = true
    }
  }
}
